package com.gitee.vincentzyu.qwq_forge189.block;

import com.gitee.vincentzyu.qwq_forge189.common.EventLoader;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.stats.Achievement;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;

public class QwqBlock extends Block {
    public QwqBlock(){
        super(Material.ground);
        this.setUnlocalizedName("qwqBlock");
        this.setHardness(1F);
        this.setStepSound(soundTypeAnvil);
    }

    @Override
    public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
        super.onBlockClicked(worldIn, pos, playerIn);
    }

    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
                                    EnumFacing side, float hitX, float hitY, float hitZ) {
        EventLoader.QwqEvent e = new EventLoader.QwqEvent(playerIn, pos, worldIn);
        EventLoader.EVENT_BUS.post(e);
        if (!e.isCanceled() && !worldIn.isRemote){
//            worldIn.setBlockToAir(pos);
//            MinecraftServer server = MinecraftServer.getServer();
//            for (EntityPlayerMP player: server.getConfigurationManager().getPlayerList()){
//                player.addChatMessage();
//            }
            EntityPlayer player = e.entityPlayer;
            player.addChatMessage(new ChatComponentText("【qwq】点我干什喵！"));

            EntityPlayerMP playerMP = (EntityPlayerMP) player;
            for(Achievement achievement: AchievementList.achievementList){
                if (playerMP.getStatFile().hasAchievementUnlocked(achievement)){
                    player.addChatMessage(
                            new ChatComponentText(
                                    "【qwq】玩家名：" + player.getName() + "，§a完成状态：是， §a成就名：" + achievement.getStatName().getUnformattedText()
                            )
                    );
                } else {
                    player.addChatMessage(
                        new ChatComponentText(
                            "【qwq】玩家名：" + player.getName() + "，红色: §4完成状态：否， §a成就名：" + achievement.getStatName().getUnformattedText()
                        )
                    );
                }
            }


            player.addChatMessage(
                new ChatComponentText(
                    "【qwq】read stat file: " + playerMP.getStatFile().toString()
                )
            );
            return true;
        }
        return false;
    }
}
